package com.example.controller;

import com.example.pojo.ManagedClass;
import com.example.pojo.Result;
import com.example.service.TeacherLastPageService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@CrossOrigin
public class TeacherLastPageController {

    @Autowired
    private TeacherLastPageService teacherLastPageService;
    @GetMapping("/loadAllClasses")
    public Result loadAllClasses(Integer teacherId){
        log.info("查询工号为{}的教师所教授的班级和科目",teacherId);
        List<ManagedClass> classList = teacherLastPageService.loadAllClasses(teacherId);
        return Result.success(classList);
    }

    @GetMapping("/searchAllSubjectName")
    public Result searchAllSubjectName(){
        return Result.success(teacherLastPageService.searchAllSubjectName());
    }

    //添加课程信息
    @PostMapping("/insertManageClass")
    public Result insertManageClass(@RequestBody ManagedClass managedClass){
        return teacherLastPageService.insertManageClass(managedClass);
    }

    //编辑课程信息
    @PostMapping("/updateManageClass")
    public Result updateManageClass(@RequestBody ManagedClass managedClass){
        log.info("更新课程信息：{}",managedClass);
        return teacherLastPageService.updateManageClass(managedClass);
    }

    //删除课程信息
    @DeleteMapping("/deleteManageClass")
    public Result deleteManageClass(@RequestBody ManagedClass managedClass){
        log.info("删除课程信息：{}",managedClass);
        return teacherLastPageService.deleteManageClass(managedClass);
    }
}
